home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: #define, question from a beginner
- Date: 01 Feb 1996 16:56:41 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Feb1095641@qcd.lanl.gov>
- References: <ma-010296161301@mac147.maths.uwa.edu.au> <31109AF8.423B@zess.uni-siegen.de>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: Markus Becker's message of Thu, 01 Feb 1996 11:50:32 +0100
-
- In article <31109AF8.423B@zess.uni-siegen.de> Markus Becker
- <becker@zess.uni-siegen.de> writes:
- <snip>
- ma wrote:
- snip
- > I can use #define to replace single lines#14 and 18. The
- following works.
-
- > QUESTION: Can I use one single macro fiveLines to replace lines
- from 14 to
- > 18 inclusively? I tried the following but got rejected. Is there
- any way to
- > get around it? Note that lines 14 and 18 contain local variables.
-
- You must use the "line-continuation" character -> "\"
- to continue a macro over more than one line.
-
- > #define fiveLines printf("%d, ",j); \ // macro should include
- this first ==== here
- > /* comment is part of the macro \ // <- and here
- > the comment contains a few lines \ // <- and here
-
- and so on.
-
- First, it is useless to discuss the code as it stands: this is a C
- language newsgroup and // does _not_ start a comment in C. What would
- have happened if it did is beyond me ... there is a group which
- discusses the language where C++ is discussed: you can ask there if
- you please.
-
- Second, a comment can never be a part of a macro, because each comment
- is treated as a single space before macros are recognized or
- expanded. (Or rather, by the `as if' rule: the _meaning_ of the
- program is as if the comments were replaced by spaces early on.) The \
- followed by newline (NOT \ followed by spaces followed by newline or \
- followed by // or other junk) is deleted even before the comment
- processing (but after the trigraph processing so that ??/ followed by
- newline is as good as \ followed by newline).
-
- The macro definition must appear on one line at the end of all
- this. So, remembering that comments are already removed, you do not
- need to put the line continuations inside a comment. Thus, the
- following is correct
-
- #define fiveLines printf("%d, ",j); \
- /* comment
- continues
- still */ \
- printf("%d, ",k);
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-